/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa036is.validators;

import cz.muni.fi.pa036is.dto.CommentFormTO;
import cz.muni.fi.pa036is.entity.Comment;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 *
 * @author Kuba
 */
public class CommentValidator implements Validator {

    @Override
    public boolean supports(Class<?> type) {
        return CommentFormTO.class.equals(type);
    }

    @Override
    public void validate(Object o, Errors errors) {
        
        ValidationUtils.rejectIfEmpty(errors, "comment.text", "text.empty");


        CommentFormTO comment = (CommentFormTO) o;

        if (comment.getName().length() > 100) {
            errors.rejectValue("comment.name", "name.value");
        }     
    }
}
